package pl.edu.pk.cc.client.connections;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Vector;

import org.jboss.logging.Logger;

import pl.edu.pk.cc.client.CCMain;
import pl.edu.pk.cc.common.dto.CCAgreementDTO;
import pl.edu.pk.cc.common.dto.CCCallHistoryDTO;
import pl.edu.pk.cc.common.dto.CCClientDTO;
import pl.edu.pk.cc.common.dto.CCEmploymentDTO;
import pl.edu.pk.cc.common.dto.CCLoginDataDTO;
import pl.edu.pk.cc.common.dto.CCProjectsDTO;
import pl.edu.pk.cc.common.dto.CCResourceDTO;
import pl.edu.pk.cc.common.dto.CCSaleDTO;
import pl.edu.pk.cc.common.dto.CCWorkerDTO;
import pl.edu.pk.cc.common.util.CCServerRequest;

public class CCServletCalls {

	private static final Logger logg = Logger.getLogger(CCServletCalls.class);
	private static String connectionURL;
	private static URL url;
	private static URLConnection connection;

	/**
	 * Initializes settings
	 * 
	 * @param serverURL
	 * @return true if initialized properly
	 */
	public static boolean init(String serverURL) {
		connectionURL = serverURL;
		try {
			url = new URL(serverURL);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		logg.info("Init -OK!");
		return true;
	}

	private CCServletCalls() {
	}

	/**
	 * @SuppressWarnings("unchecked") protected List<CCResourceDTO> getResourceByID(long sessionID, Vector<Object> args) { logg.info("Getting resources"); List<CCResourceDTO> results = null;
	 *                                CCServerRequest request = new CCServerRequest(sessionID, "CCServletRequestExecutor", "getResourcesByID", args); try { connection = url.openConnection();
	 *                                connection .setRequestProperty("Content-Type", "application/x-java-serialized-object"); } catch (IOException e1) { e1.printStackTrace(); }
	 *                                connection.setDoOutput(true); connection.setDoInput(true);
	 * 
	 *                                try (ObjectOutputStream output = new ObjectOutputStream (connection.getOutputStream())) { output.writeObject(request); output.flush(); } catch (Exception e) {
	 *                                e.printStackTrace(); }
	 * 
	 *                                try (ObjectInputStream input = new ObjectInputStream (connection.getInputStream())) { results = (List<CCResourceDTO>) input.readObject(); } catch (Exception e) {
	 *                                e.printStackTrace(); } logg.info("Getting resources -OK!"); return results; }
	 * @SuppressWarnings("unchecked") protected List<CCResourceDTO> getResourceByString(long sessionID, Vector<Object> args) { logg.info("Getting resources"); List<CCResourceDTO> results = null;
	 *                                CCServerRequest request = new CCServerRequest(sessionID, "CCServletRequestExecutor", "getResourcesByString", args); try { connection = url.openConnection(); }
	 *                                catch (IOException e1) { e1.printStackTrace(); } connection.setDoOutput(true); connection.setDoInput(true);
	 * 
	 *                                try (ObjectOutputStream output = new ObjectOutputStream (connection.getOutputStream())) { output.writeObject(request); output.flush(); } catch (Exception e) {
	 *                                e.printStackTrace(); }
	 * 
	 *                                try (ObjectInputStream input = new ObjectInputStream (connection.getInputStream())) { results = (List<CCResourceDTO>) input.readObject(); } catch (Exception e) {
	 *                                e.printStackTrace(); } logg.info("Getting resources -OK!"); return results; }
	 */

	@SuppressWarnings("unchecked")
	protected static Vector<Object> login(String login, String password) {
		logg.info("Getting session");
		Vector<Object> results = null;
		Vector<String> args = new Vector<>();
		args.add(login);
		args.add(password);
		CCServerRequest request = new CCServerRequest(0, "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "login", args);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<Object>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting session -OK!");
		return results;
	}

	protected static void logout(long sessionID) {
		logg.info("Closing session");
		List<Long> args = new Vector<>();
		args.add(CCMain.getCurrentSession().getSessionID());
		args.add(CCMain.getCurrentSession().getUserID());
		CCServerRequest request = new CCServerRequest(sessionID, "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "logout", args);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
			output.flush();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			Object results = input.readObject();// Ignore
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Closing session -OK!");
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCAgreementDTO> getAgreementByID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCAgreementDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getAgreementByID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCAgreementDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCAgreementDTO> getAgreementByClientID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCAgreementDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getAgreementByClientID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCAgreementDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCCallHistoryDTO> getCallHistoryByID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCCallHistoryDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getCallHistoryByID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCCallHistoryDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCCallHistoryDTO> getCallHistoryByClientID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCCallHistoryDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getCallHistoryByID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCCallHistoryDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCCallHistoryDTO> getCallHistoryByWorkerID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCCallHistoryDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getCallHistoryByWorkerID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCCallHistoryDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCClientDTO> getClientByID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCClientDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getClientByID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCClientDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCClientDTO> getClientByName(Vector<String> params) {
		logg.info("Getting resources");
		Vector<CCClientDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getClientByName", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCClientDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCClientDTO> getClientByAddress(Vector<String> params) {
		logg.info("Getting resources");
		Vector<CCClientDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getClientByAddress", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCClientDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCEmploymentDTO> getEmploymentByID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCEmploymentDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getEmploymentByID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCEmploymentDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCEmploymentDTO> getEmploymentByPlacement(Vector<String> params) {
		logg.info("Getting resources");
		Vector<CCEmploymentDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getEmploymentByPlacement", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCEmploymentDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCEmploymentDTO> getEmploymentByWorkerID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCEmploymentDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getEmploymentByWorkerID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCEmploymentDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCSaleDTO> getSaleByID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCSaleDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getSaleByID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCSaleDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCSaleDTO> getSaleByClientID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCSaleDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getSaleByClientID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCSaleDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCWorkerDTO> getWorkerByID(Vector<Long> params) {
		logg.info("Getting resources");
		Vector<CCWorkerDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getWorkerByID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCWorkerDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCWorkerDTO> getWorkerByName(Vector<String> params) {
		logg.info("Getting resources");
		Vector<CCWorkerDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getWorkerByName", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCWorkerDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	protected static Vector<CCWorkerDTO> getWorkerByLogin(Vector<String> params) {
		logg.info("Getting resources");
		Vector<CCWorkerDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getWorkerByLogin", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCWorkerDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	protected static void saveData(Vector<CCResourceDTO> data) {
		logg.info("Saving data");
		String method = "";
		if (data.get(0).getClass() == CCAgreementDTO.class) {// TODO - check maybe need instanceof here
			method = "saveAgreement";
		} else if (data.get(0).getClass() == CCEmploymentDTO.class) {
			method = "saveEmployment";
		} else if (data.get(0).getClass() == CCCallHistoryDTO.class) {
			method = "saveCallHistory";
		} else if (data.get(0).getClass() == CCLoginDataDTO.class) {
			method = "saveLoginData";
		} else if (data.get(0).getClass() == CCClientDTO.class) {
			method = "saveClient";
		} else if (data.get(0).getClass() == CCSaleDTO.class) {
			method = "saveSale";
		} else if (data.get(0).getClass() == CCWorkerDTO.class) {
			method = "saveWorker";
		} else {
			System.out.println("No match!");
		}
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", method, data);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			Object results = input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}

		logg.info("Data saved!");
	}

	public static String getConnectionURL() {
		return connectionURL;
	}

	@SuppressWarnings("unchecked")
	public static Vector<CCClientDTO> getClientByWorkerID(Vector<Long> params) {// TODO
		logg.info("Getting resources");
		Vector<CCClientDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getClientByWorkerID", params);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCClientDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	public static Vector<CCAgreementDTO> getAgreementAll() {
		logg.info("Getting resources");
		Vector<CCAgreementDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getAgreementAll", null);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCAgreementDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	public static Vector<CCProjectsDTO> getProjectsAll() {
		logg.info("Getting resources");
		Vector<CCProjectsDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getProjectsAll", null);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCProjectsDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	public static Vector<CCClientDTO> getClientsRand() {
		logg.info("Getting resources");
		Vector<CCClientDTO> results = null;
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getClientsRand", null);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<CCClientDTO>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

	@SuppressWarnings("unchecked")
	public static Vector<String> getScriptByType(String type) {
		logg.info("Getting resources");
		Vector<String> results = null;
		Vector<String> args = new Vector<>();
		args.add(type);
		CCServerRequest request = new CCServerRequest(CCMain.getCurrentSession().getSessionID(), "pl.edu.pk.cc.server.main.CCServletRequestExecutor", "getScriptByType", args);
		try {
			connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try (ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream())) {
			output.writeObject(request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		try (ObjectInputStream input = new ObjectInputStream(connection.getInputStream())) {
			results = (Vector<String>) input.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		logg.info("Getting resources done!");
		return results;
	}

}
